// components/num/num.js
Component({
  properties: {
    price: {
      type: String,
      value: ""
    },
    quantity: {
      type: Number,
      value: 0
    },
    index: {
      type: Number,
      value: 0
    }
  },

  data: {
    // num 不再需要记录数量，因为已经由外部传递
  },

  methods: {
    subtract() {
      if (this.properties.quantity > 1) {
        this.triggerEvent('changeQuantity', {
          index: this.properties.index,
          price: this.properties.price,
          quantity: this.properties.quantity - 1
        });
      }
    },
    add() {
      this.triggerEvent('changeQuantity', {
        index: this.properties.index,
        price: this.properties.price,
        quantity: this.properties.quantity + 1
      });
    }
  }
});